﻿using System.Diagnostics;
using System.Text;

namespace _28_C_中的StringBuilder
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "C#中的StringBuilder";

            //Stopwatch sw = Stopwatch.StartNew();

            //sw.Start();

            //string str = "";
            //for (int i = 0; i < 100000; i++) {
            //    str += "a";
            //}

            //sw.Stop();
            //Console.WriteLine("string+=的耗时："+sw.ElapsedMilliseconds);

            //Stopwatch sw1 = Stopwatch.StartNew();

            ////stringbuilder
            //sw1.Start();

            //StringBuilder str1 = new StringBuilder();
            //for (int i = 0; i < 100000; i++)
            //{
            //    str1.Append("a");
            //}

            //sw1.Stop();

            //Console.WriteLine("stringbuilder的耗时：" + sw1.ElapsedMilliseconds);

            //预留 50 个字符的空间，以减少将来对其进行修改（如追加字符）时的内存重新分配
            StringBuilder sb =new StringBuilder("123456789",50);

            //sb.Remove(2,4);
            //sb.Replace('3','a');
            //sb.Insert(2,"aaa");

            DateTime dateTime = DateTime.Now;
            sb.AppendFormat("当前时间：{0:yyyy/MM/dd HH-mm:ss}",dateTime);
            Console.WriteLine(sb.ToString());

            Console.ReadKey();
        }
    }
}
